﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="WebPublished.aspx.cs" Inherits="news_WebPublished" %>

<%@ Register src="Module.ascx" tagname="Module" tagprefix="uc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link href="../css/style.css" rel="stylesheet" type="text/css" />
    <script src="../js/jquery-1.3.2.min.js" type="text/javascript">
    </script>
    <script src="../js/jquery-ui-1.7.3.custom.min.js" language="javascript" type="text/javascript"></script>
    <link href="../css/jquery-ui-1.7.3.custom.css" rel="Stylesheet" type="text/css" />

    <script type="text/javascript" language="javascript">
        $(document).ready(function () {
            $("#divPageAdd").hide();
            $("#btnAdd").click(function () {
                if ($("#divPageAdd").css("display") == 'none') {
                    $("#btnAdd").val("隐藏");
                    $("#divPageAdd").show(1000);
                }
                else {
                    $("#divPageAdd").hide(1000);
                    $("#btnAdd").val("添加");
                }
            })

            $("#btnSave").click(function () {
                var pageId = $("#txtPageId").val();
                var pageName = $("#txtPageName").val();
                if (pageId == "") {
                    alert("页面编号不能为空");
                    return false;
                }
                if (pageName == "") {
                    alert("页面名称不能为空");
                    return false;
                }
                $.post("WebPublishedAdd.ashx", { PageId: pageId, PageName: pageName }, function (data) {
                    if (data == "-1") {
                        alert("页面编号已经存在")
                    }
                    if (data == "-2") {
                        alert("页面名称已经存在")
                    }
                    if (data == "1") {
                        alert("添加成功");
                        document.location = document.location;
                    }
                })
                return false;
            })

            $('#dialog').dialog({
                autoOpen: false,
                modal: true,
                width: 300,
                buttons: {
                    "取消": function () {
                        $(this).dialog("close");
                    },
                    "确定": function () {
                        var moduleId = $("#txtModuleId").val();
                        var pageId = $("#hidPageId").val();
                        var moduleName = $("#txtModuleName").val();
                        var hangshu = $("#txtHangshu").val();
                        var zishu = $("#txtZishu").val();
                        if (moduleId == "") {
                            alert("模块编号不能为空");
                            return;
                        }
                        if (pageId == "") {
                            alert("请选择页面编号");
                            return false;
                        }
                        if (moduleName == "") {
                            alert("模块名称不能为空");
                            return false;
                        }
                        if (hangshu == "") {
                            alert("行数不能为空");
                            return false;
                        }
                        var c = /^[1-9]\d*$/
                        if (!c.test(hangshu)) {
                            alert("行数必须为正整数");
                            return false;
                        }
                        $.post("PublishedModuleAdd.ashx", { ModuleId: moduleId, ModuleName: moduleName, PageId: pageId, hangshu: hangshu }, function (data) {
                            if (data == "-1") {
                                alert("这个模块编号已经存在");
                                return false;
                            }
                            if (data == "-2") {
                                alert("这个模块名称已经存在");
                                return false;
                            }
                            if (data == 1) {
                                alert("添加成功");
                                document.location = document.location;
                                return false;
                            }
                        })
                    }
                }
            });
            $("[name=addModule]").click(function () {
                $("#hidPageId").val($(this).attr("pageId"));
                $('#dialog').dialog('open');
                return false;
            })
        })
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div>   
        <input id="btnAdd" value="添加页面" type="button"  />
        <div  id="divPageAdd">
            页面编号
            <asp:TextBox ID="txtPageId" runat="server" Width="100px" />
            页面名称
            <asp:TextBox ID="txtPageName" runat="server" Width="100px" />
            <asp:Button ID="btnSave" runat="server" Text="保存" />
        </div>
    </div>
    <div>
        <asp:Repeater ID="Repeater1" runat="server">
            <ItemTemplate>
                 <uc1:Module ID="Module1" runat="server" PageId='<%# Eval("PageId") %>' />
            </ItemTemplate>
        </asp:Repeater>
    </div>

    <div id="dialog" title="添加模块" >
        <p id="content" style="text-align: center">
            <input type="hidden" id="hidPageId" />
            模块编号<input id="txtModuleId" type="text" /><br />
            模块名称<input id="txtModuleName" type="text" /><br />
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;行数<input id="txtHangshu" type="text" value="7" />
        </p>
    </div>
    </form>
</body>
</html>
